<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>销售出库</title>
    <jsp:include page="../headPage.jsp"></jsp:include>
    <script type="text/javascript">
    
    function toastrStyle(){
    	toastr.options = {
                "closeButton": false,
                "debug": false,
                "newestOnTop": false,
                "progressBar": false,
                "positionClass": "toast-top-center",
                "preventDuplicates": false,
                "onclick": null,
                "showDuration": "5000",
                "hideDuration": "1000",
                "timeOut&quot": "100000",
                "extendedTimeOut": "0",
                "showEasing": "swing",
                "hideEasing": "linear",
                "showMethod": "fadeIn",
                "hideMethod": "fadeOut"
            }; 
    }
    
    $(function () {

            //1.初始化Table
            var oTable = new TableInit();
            oTable.Init();

            //2.初始化Button的点击事件
            var oButtonInit = new ButtonInit();
            oButtonInit.Init();

            //行点击事件
            $('#tb_departments').on('click-row.bs.table', function (e, row, element) {initBottomTable(row.id);});

        });


        var TableInit = function () {
            var oTableInit = new Object();
            //初始化Table
            oTableInit.Init = function () {
                $('#tb_departments').bootstrapTable({
                    url: '${pageContext.request.contextPath }/yzl/outLibOrderList.do',         //请求后台的URL（*）
                    method: 'post',                      //请求方式（*）
                    contentType:"application/x-www-form-urlencoded; charset=UTF-8",
                    toolbar: '#toolbar',                //工具按钮用哪个容器
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    queryParams: oTableInit.queryParams,//传递参数（*）
                    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                       //初始化加载第一页，默认第一页
                    pageSize: 10,                       //每页的记录行数（*）
                    pageList: [10, 20, 30],        //可供选择的每页的行数（*）
                    maintainSelected: false,
                    minimumCountColumns: 2,             //最少允许的列数
                    height: 400,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                    columns: [{
                        checkbox: true
                    }, /*{
                        field: 'id',
                        title: 'ID'
                    },*/ {
                        field: 'outNumber',
                        title: '出库单号'
                    }, {
                        field: 'outDate',
                        title: '出库日期'
                    }, {
                        field: 'customerName',
                        title: '客户'
                    },/* {
                        field: 'outLibQ',
                        title: '数量'
                    },*/ {
                        field: 'outStatus',
                        title: '状态',
                        formatter:function(value, row, index){
                            if(value == 0){
                                return '未出库'
                            }else if(value == 1){
                                return '已出库'
                            }else{
                                return 'WTF'
                            }
                        }
                    }, {
                        field: 'spStatus',
                        title: '审批状态',
                        formatter: function (value, row, index) {
                            var back = index;
                            if (value == "0") {
                                return '未提交'
                            } else if (value == "1") {
                                return '审批中'
                            } else if (value == "2") {
                                return '审批完成'
                            } else if (value == "3") {
                                return '审批未通过'
                            } else {
                                return 'WTF'
                            }
                        }
                    }]
                });
            };

            //得到查询的参数
            oTableInit.queryParams = function (params) {
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,   //页面大小
                    offset: params.offset/params.limit+1,  //页码
                    recent: $("#recent").val(),
                    beginDate: $("#beginDate").val(),
                    endDate: $("#endDate").val(),
                    customerName: $("#customerName").val(),
                };
                return temp;
            };
            return oTableInit;
        };


        var ButtonInit = function () {

            var oInit = new Object();
            var postdata = {};

            oInit.Init = function () {
                //初始化页面上面的按钮事件
            };
            return oInit;
        };
        
        $(function() {
        	//执行后台
            $.ajax({
                url: "${pageContext.request.contextPath}/hpf/customerAllList.do",
                type: "post",
                success: function (data) {
                	//var row = data.rows;
                	for(var i=0;i<data.length;i++){
                    	console.log(data[i]);
                		//添加option
                    	$("#customerName").append("<option>" + data[i].name + "</option>");
                	}
                }
            })
		})
    </script>
</head>
<body>
<div class="panel-body" style="padding-bottom:0px;">
    <!--   查询条件  -->
    <div class="panel panel-default">
    	<div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <form id="formSearch" class="form-horizontal">
                <label class="control-label col-sm-1">日期:</label>
                <div class="col-sm-2">
                    <select id="recent" name="recent"
                            class="selectpicker show-tick form-control" data-live-search="false">
                        <option value="0">所有时间</option>
                        <option value="1">最近一天</option>
                        <option value="7">最近一星期</option>
                        <option value="30">最近一个月</option>
                    </select>
                </div>
                <label class="control-label col-sm-1" for="beginDate" style="width: 30px;">从</label>
                <div class="col-sm-2">
                    <input type="text" name="beginDate" id="beginDate" placeholder="yyyy-mm-dd" class="form_datetime form-control">
                </div>
                <label class="control-label col-sm-1" for="endDate" style="width: 30px;padding-left: 0px;">至</label>
                <div class="col-sm-2" style="padding-left: 0px;">
                    <input type="text" name="endDate" id="endDate" placeholder="yyyy-mm-dd" class="form_datetime form-control">
                </div>
                <label class="control-label col-sm-1" for="customerName">相关客户:</label>
                <div class="col-sm-1">
                    <select id="customerName" name="customerName"
                            class="selectpicker show-tick form-control" data-live-search="false">
                        <option>所有客户</option>
                    </select>
                </div>
                <div class="col-sm-1">
                    <button type="button" id="btn_query" class="btn btn-primary">查询</button>
                </div>
                <!-- <div class="col-sm-1">
                    <button type="button" id="btn_query1" class="btn btn-default">清除</button>
                </div> -->
                <%--</div>--%>
            </form>
        </div>
    </div>

    <div id="toolbar" class="btn-group">
        <button id="btn_add" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
        </button>
        <button id="btn_edit" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
        </button>
        <button id="btn_delete" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
        </button>
        <button id="btn_approved" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-phone" aria-hidden="true"></span>审批
        </button>
        <!-- <button id="btn_approved2" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量审批
        </button> -->
        <button id="btn_Undoapproved" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>撤销审批
        </button>
        <button id="btn_Export" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-inbox" aria-hidden="true"></span>导出
        </button>
        <!-- <button id="btn_Export1" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>出库处理
        </button> -->
    </div>



    <!--        表格           -->
    <table id="tb_departments" style="font-size: 14px;"></table>

    <!--    底部详情表格   -->
    <div id="bottomTableDiv"></div>

    <!--          添加表单       -->
    <%--<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 70%;height: 60%">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel">新增订单</h4>
                </div>

                <div id="addModelTable_outDiv"></div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary">确定</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>--%>


    <div class="modal fade" id="salePlanModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 60%;height: 50%">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="salePlanModelLabel">销售计划</h4>
                </div>

                <div id="img"></div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="backOutLib()" id="backOutLib">确定</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
    
    <!--    删除   -->
    <div class="modal fade" id="myModalDelete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 40%;height: 50%">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalDeleteLabel">删除确认</h4>
                </div>



                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="deleteOrder()">确定删除</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>


    <!--          销售计划选择列表       -->
    <%--<div class="modal fade" id="salePlanModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 60%;height: 50%">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="salePlanModelLabel">销售计划</h4>
                </div>

                <table id="td_salePlanTable"></table>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="backOutLib()" id="backOutLib">确定</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>--%>

</div>



<script>


        $("#btn_edit").click(function () {

            if ($('#checkbox-id').is(':checked')) {}

            $('#myModalUpdate').modal({})
        });
        
        $("#btn_delete").click(function () {

            //必须选中一条数据
        	var checkedItems = $('#tb_departments').bootstrapTable('getSelections');
            if(checkedItems <= 0){
            	toastrStyle();
                toastr.warning('请选择一行信息');
            }else{
                console.log("checkedItems----",checkedItems);
                var arr1 = filterData(checkedItems);
                if(arr1){
                	var arr2 = filterOutData(checkedItems);
                    if(arr2){
                    	//询问框
                		Ewin.confirm({message : "确认要删除选择的数据吗？"}).on(
                			function(e) {
                				if (!e) {return;}
                				$.ajax({
                                    url: "${pageContext.request.contextPath}/yzl/deleteOutLibOrder.do",
                                    type: "post",
                                    data: {"arr": JSON.stringify(arr2)},
                                    success: function (data) {
                                        if (data != 0) {
                                        	toastrStyle();
                                            toastr.info('删除成功');
                                            refreshAjax();
                                        } else {
                                        	toastrStyle();
                                            toastr.warning('删除失败');
                                        }
                                    }
                                })
                			});
                    }else{
                    	toastrStyle();
                        toastr.warning('不能删除已出库的出库记录');
                    }
                }else{
                	toastrStyle();
                    toastr.warning('不能删除审核中或已审核的出库记录');
                }
            }
        });

        function deleteOrder(){

            var checkedItems = $('#tb_departments').bootstrapTable('getSelections');
            //var checkedItem = checkedItems[0];
            var list=new Array(checkedItems.length);
            for (var i=0;i<checkedItems.length;i++) {
            	list[i]=checkedItems[i].id;
            }
            console.log(list);
            $("#myModalDelete").modal('hide');
            //comAjax("${pageContext.request.contextPath}/yzl/deleteOrder.do",{id:checkedItem.id},function(data){})
            var arr1 = filterData(checkedItems);
            if (arr1) {
            	var arr2 = filterOutData(checkedItems);
                if (arr2) {
                    //执行后台
                    $.ajax({
                        url: "${pageContext.request.contextPath}/yzl/deleteOutLibOrder.do",
                        type: "post",
                        data: {"arr": JSON.stringify(arr2)},
                        success: function (data) {
                            if (data != 0) {
                                toastr.info('操作成功');
                                refreshAjax();
                            } else {
                                toastr.warning('操作失败');
                            }
                        }
                    })
                }
            }
            window.location.href = "${pageContext.request.contextPath }/pages/yzlERP/outLibrary/salesOutLibrary.jsp";
        }

        $("#btn_query").click(function (){refreshAjax();})

        function backOutLib(){
            //得到选择的数据
            var rows = $('#td_salePlanTable').bootstrapTable('getSelections')[0];
            //得到原来的表头信息
            var objTable = dedaoValue("td_addModelTable");
            if(rows){
                //关闭第二层模态框
                $("#backOutLib").attr("data-dismiss","modal");
                //更新第一层模态框的表格
                initAddTable(objTable.number,objTable.time,"张三","李四",rows.orderNumber,"王五");
            }else{
            	toastrStyle();
            	toastr.warning("请选择客户");
            }
        }

    //提交审核
    $("#btn_approved").click(function (){
        //必须选中一条数据
        var checkedItems = $('#tb_departments').bootstrapTable('getSelections');
        var checkedItem = checkedItems[0];
        if(checkedItems <= 0){
            //$("#btn_edit").attr("data-toggle", "");
            //$("#btn_edit").attr("data-target", "");
            toastrStyle();
            toastr.warning('请选择一行信息');
        }else{
            console.log("checkedItems----",checkedItems);
            var arr = filterData(checkedItems);
            console.log("arr",arr);
            if(arr){
                //执行后台
                $.ajax({
                    url:"${pageContext.request.contextPath}/yzl/outlibApproveds.do",
                    type:"post",
                    data:{"arr":JSON.stringify(arr)},
                    success:function (data) {
                        if(data != 0){
                        	toastrStyle();
                            toastr.info('提交审批成功');
                            refreshAjax();
                        }else{
                        	toastrStyle();
                            toastr.warning('提交审批失败');
                        }
                    }
                })
            }else{
            	toastrStyle();
                toastr.warning('只能选择未审批的出库单号');
            }
        }
    })
    
    
    //撤销审核
    $("#btn_Undoapproved").click(function (){
        //必须选中一条数据
        var checkedItems = $('#tb_departments').bootstrapTable('getSelections');
        var checkedItem = checkedItems[0];
        if(checkedItems <= 0){
            //$("#btn_edit").attr("data-toggle", "");
            //$("#btn_edit").attr("data-target", "");
            toastrStyle();
            toastr.warning('请选择一行信息');
        }else{
            console.log("checkedItems----",checkedItems);
            var arr = filterDataUn(checkedItems);
            console.log("arr",arr);
            if(arr){
                //执行后台
                $.ajax({
                    url:"${pageContext.request.contextPath}/yzl/outlibUnApproveds.do",
                    type:"post",
                    data:{"arr":JSON.stringify(arr)},
                    success:function (data) {
                        if(data != 0){
                        	toastrStyle();
                            toastr.info('撤销成功');
                            refreshAjax();
                        }else{
                        	toastrStyle();
                            toastr.warning('撤销失败');
                        }
                    }
                })
            }else{
            	toastrStyle();
                toastr.warning('不能选择未审核或已审核的出库单号');
            }
        }
    })
    
    //导出
    $("#btn_Export").click(function (){
    	//询问框
		Ewin.confirm({message : "确认要导出所有数据吗？"}).on(
			function(e) {
				if (!e) {return;}
				window.location.href="${pageContext.request.contextPath}/yzl/outlibImport.do"
			});
    })
    
    //出库处理
    $("#btn_Export1").click(function (){
        //必须选中一条数据
        var checkedItems = $('#tb_departments').bootstrapTable('getSelections');
        var checkedItem = checkedItems[0];
        if(checkedItems <= 0){
            //$("#btn_edit").attr("data-toggle", "");
            //$("#btn_edit").attr("data-target", "");
            toastrStyle();
            toastr.warning('请选择一行信息');
        }else{
            console.log("checkedItems----",checkedItems);
            var arr1 = filterData1(checkedItems);
            if(arr1){
            	var arr2 = filterOutData(checkedItems);
            	if(arr2){
            		//执行后台
                    $.ajax({
                        url:"${pageContext.request.contextPath}/yzl/libOutbound.do",
                        type:"post",
                        data:{"arr":JSON.stringify(arr2)},
                        success:function (data) {
                            if(data != 0){
                            	toastrStyle();
                                toastr.info('出库成功');
                                refreshAjax();
                            }else{
                            	toastrStyle();
                                toastr.warning('出库失败');
                            }
                        }
                    })
            	}else{
            		toastrStyle();
            		toastr.warning('不能选择已出库的出库单号');
            	}
            }else{
            	toastrStyle();
                toastr.warning('只能选择已审批的出库单号');
            }
        }
    })



    //关闭计划
    function closePlan(index){
        var id = $("#tb_departments").bootstrapTable('getData')[index].id;
        $.ajax({
            url:"${pageContext.request.contextPath}/yzl/closePlan.do",
            type:"post",
            data:{"id":id},
            success:function (data) {
                if(data != 0){
                    toastr.info('操作成功');
                    refreshAjax();
                }else{
                    toastr.warning('操作失败');
                }
            }
        })
    }


    //选择销计划单号
    function chosePlanNum(){
        initSaleTable();
    }

    //计划详情
    function planXq(){
        //initBottomTable();
    }

  	//选中数据条件筛选（是否出库）
    function filterOutData(checkedItems){
        var arr = new Array();
        for (var i = 0; i < checkedItems.length; i++) {
            var outStatus = checkedItems[i].outStatus;
            if (outStatus == "1") {
                return false
            } else {
                arr.push(checkedItems[i].id);
            }
        }
        return arr;
    }
    
    //选中数据条件筛选
    function filterDataUn(checkedItems){
        var arr = new Array();
        for(var i=0;i<checkedItems.length;i++){
            var spStatus = checkedItems[i].spStatus;
            if(spStatus == "2" || spStatus == "0"){
                return false
            }else{
                arr.push(checkedItems[i].id);
            }
        }
        return arr;
    }
    
    //选中数据条件筛选
    function filterData(checkedItems){
        var arr = new Array();
        for(var i=0;i<checkedItems.length;i++){
            var spStatus = checkedItems[i].spStatus;
            if(spStatus == "2" || spStatus == "1"){
                return false
            }else{
                arr.push(checkedItems[i].id);
            }
        }
        return arr;
    }
    
    //选中数据条件筛选
    function filterData1(checkedItems){
        var arr = new Array();
        for(var i=0;i<checkedItems.length;i++){
            var spStatus = checkedItems[i].spStatus;
            if(spStatus != "2"){
                return false
            }else{
                arr.push(checkedItems[i].id);
            }
        }
        return arr;
    }

    function makeRequirement() {
        $('#requirementModel').modal({
            keyboard: true,
        })
    }

    function xiangqing() {
        $('#xiangqingModel').modal({
            keyboard: true,
        })
    }

    function tiJiao() {
        $('#layui-layer20').modal({
            keyboard: true,
        })
    }


    //点击查询 重新请求  刷新表格
    function refreshAjax(){
        $("#tb_departments").bootstrapTable('refresh',{url : '${pageContext.request.contextPath }/yzl/outLibOrderList.do'});
    }
</script>


<script>

    //底部详情列表初始化
    function initBottomTable(id){
        var $bottomTableDiv = $("#bottomTableDiv");
        if($bottomTableDiv.find("table").length > 0){
            url = "${pageContext.request.contextPath }/yzl/outOrderXq.do?id="+id;
            $("#tb_details").bootstrapTable('refresh', {url: url});
            //$bottomTableDiv.empty();
        }else{
            var table = '<table id="tb_details" style="font-size: 14px;"></table>'
            $bottomTableDiv.append(table);
        }

        $('#tb_details').bootstrapTable({
            dataType: "json",
            method: 'get',
            contentType: "application/x-www-form-urlencoded",
            cache: false,
            toolbar: '#toolbarIn',
            url: "${pageContext.request.contextPath }/yzl/outOrderXq.do?id="+id,
            height:300,
            columns: [
                [
                    {
                        field: 'cartype',
                        title: '车种',
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'num',
                        title: '品编',
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'name',
                        title: '品名',
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'outQ',
                        title: '出库数量',
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'remark8',
                        title: '单价',
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'amount',
                        title: '金额',
                        valign: "middle",
                        align: "center",
                        formatter: function (value, row, index) {
                            return accMul(row.outQ,row.remark8);
                        }
                    }/* ,
                    {
                        field: 'dayConsumptionQ',
                        title: '日消耗量',
                        valign: "middle",
                        align: "center"
                    } */

                ]
            ]
        });
    }

    //初始化销售计划单
    function initSaleTable(){
        $('#td_salePlanTable').bootstrapTable({
            dataType: "json",
            method: 'get',
            contentType: "application/x-www-form-urlencoded",
            cache: false,
            singleSelect : true, // 单选checkbox
            url:"/pages/yzlERP/data/salesPlanOut.json",
            columns: [
                [
                {
                    checkbox: true
                },
                {
                    field: 'orderNumber',
                    title: '计划单号'
                }, {
                    field: 'customer',
                    title: '客户'
                }, {
                    field: 'status',
                    title: '发货状态',
                    formatter: function (value, row, index) {
                        if (value == 0) {
                            return '未发货'
                        } else if (value == 1) {
                            return '已发货'
                        } else {
                            return 'WTF'
                        }

                    }
                }]
                ]
        });
        $('#salePlanModel').modal({
            keyboard: true,
        })
    }

    //更具传入的表格ID 查询数据

    function dedaoValue(tableId){

        //拿到原来表格中填写的订单号和时间
        var $thead  = $($($("#"+tableId)[0]).find("thead")[0]);
        //拿到第一行
        var $tr1 = $($thead.find("tr")[0]);
        //拿到订单号
        var number = $($($tr1.find("th")[1]).find("div")[0]).text();
        //拿到时间
        var time = $("#addTime").val();


        //拿到第二行
        var $tr2 = $($thead.find("tr")[1]);
        //拿到客户名称
        var customer = $($($tr2.find("th")[1]).find("div")[0]).text();
        console.log("customer--",customer);
        var obj = {
            number : number,
            time : time,
            customer : customer
        };
        return obj;
    }

</script>

<!--    时间插件    -->

<script>
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form(),
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            title: function(value) {
                if(value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            },
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            content: function(value) {
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(demo1)', function(data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });
    });
</script>
<script type="text/javascript">
 $(function () {
	$(".form_datetime").datetimepicker({
	 format: "yyyy-mm-dd",
	 autoclose: true,
	 todayBtn: true,
	 todayHighlight: true,
	 showMeridian: true,
	 pickerPosition: "bottom-left",
	 language: 'zh-CN',//中文，需要引用zh-CN.js包
	 startView: 2,//月视图
	 minView: 2//日期时间选择器所能够提供的最精确的时间选择视图
	 });
 });
</script>
<script>
        //循环获取父层的tab对象，为什么用循环呢？因为子层加载完，父层还不一定加载完了。所以获取到的是undefined
        /*var index = setInterval(function() {
            if(typeof parent.tab !== 'undefined') {
                //如果获取到tab对象，则停止循环
                clearInterval(index);
                //通过调用父层的tab组件里的tabAdd方法添加一个tab选项卡
                parent.tab.tabAdd({
                    href: 'https://www.baidu.com', //地址
                    icon: 'fa-user',
                    title: '这是在子窗口打开的tab选项卡'
                });
            }
        }, 20);*/
        //如果需要在些页面上获取到父页面的变量，需要把变量设置为全局，
        /**
         * 例：
         * var tab;
         * layui.use('tab',function(){
         * 	   tab = layui.tab(setting);
         * });
         */
        //上面那个是页面渲染完就添加的
        layui.use(['layer'], function () {
            var aa = 111;
            var $ = layui.jquery,
                layer = layui.layer;

            //移除当前的选项卡
            $('#remove').on('click', function () {
                var tab = parent.tab;

                tab.deleteTab(tab.getCurrentTabId());
            });

            //这个是点击之后才添加的。
            $('#btn_add').on('click', function () {

                window.location.href = "${pageContext.request.contextPath}/pages/yzlERP/outLibrary/add.jsp";

                //这是核心的代码。
                /*parent.tab.tabAdd({
                    href: "/pages/yzlERP/outLibrary/add.jsp", //地址
                    icon: "",
                    title: "添加"
                });*/
            });
            $('#btn_edit').on('click', function () {

                //必须选中一条数据
                var checkedItems = $('#tb_departments').bootstrapTable('getSelections');
                var checkedItem = checkedItems[0];
				console.log(checkedItem);
                if(checkedItems.length == 0){
                	toastrStyle();
                    toastr.warning('请选择一行信息');
                }else if(checkedItems.length == 1){
                	if(checkedItem.spStatus!='0'){
                		toastrStyle();
                		toastr.warning('只能修改未审批的信息');
                	}else{
                		window.location.href = "${pageContext.request.contextPath}/pages/yzlERP/outLibrary/update.jsp?id="+checkedItem.id;
                	}
                } else{
                	toastrStyle();
                	toastr.warning('只能修改一行信息');
                }

            });

        });
    </script>

</body>
</html>
